﻿using ConfExpert.Forms.Base;
using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Siparisler
{
    public partial class MaliyetList : XForm
    {
        public MaliyetList()
        {
            InitializeComponent();
        }

        public int MaliyetId = 0;
        BindingSource bs;
        private void MaliyetList_Load(object sender, EventArgs e)
        {
            TAM.MaliyetTableAdapter = new ConfExpert.Datasets.MyDataTableAdapters.MaliyetTableAdapter();
            TAM.MaliyetTableAdapter.Fill(ds.Maliyet);

            bs = new BindingSource(ds, "Maliyet");
            AddBsToList(bs);
            InitGridView(gridView1, bs);
            gridView1.BestFitColumns();
            //gridView1.OptionsBehavior.Editable = false;
            gridView1.DoubleClick += new EventHandler(gridView1_DoubleClick);
            btnOpen.ItemClick += btnOpen_ItemClick;
            btnSave.ItemClick += btnSave_ItemClick;

            gridView1.ShowingEditor += new System.ComponentModel.CancelEventHandler(gridView1_ShowingEditor);
            //gridView1.OptionsView.EnableAppearanceEvenRow = false;
        }

        void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
        }

        void btnOpen_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            throw new NotImplementedException();
        }

        void gridView1_DoubleClick(object sender, EventArgs e)
        {
            MaliyetId = intParse(bs, "MaliyetId");
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        //void gridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        //{
        //    if (intParse(gridView1.GetRowCellValue(e.RowHandle, "MaliyetId")) < 0)
        //        e.Appearance.BackColor = Color.YellowGreen;
        //}

        void gridView1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = !(intParse(gridView1.GetFocusedRowCellValue("UserId")) == WhoAmI);
        }

    }
}